package com.settings;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.content.Context;

public class SettingsProvider {
	public static Context context;
	public static String readFile(){
		FileInputStream fIn;
		try {
			fIn = context.openFileInput("settings.txt");
			InputStreamReader isr = new InputStreamReader(fIn);
			BufferedReader br = new BufferedReader(isr);
			String strLine;
			String strBuilder = "";
			while ((strLine = br.readLine()) != null){
				strBuilder+= strLine;
				strBuilder+= "\n";
			}
			return strBuilder;
		} catch (FileNotFoundException e) {
			createFile();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	public static void createFile(){
		try {
			FileOutputStream fOut = context.openFileOutput("settings.txt", Context.MODE_WORLD_READABLE);
			OutputStreamWriter osw = new OutputStreamWriter(fOut);
			osw.flush();
			osw.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void writeFile(String content){
		try {
			FileOutputStream fOut = context.openFileOutput("settings.txt", Context.MODE_WORLD_READABLE);
			OutputStreamWriter osw = new OutputStreamWriter(fOut);
			osw.write(content);
			osw.flush();
			osw.close();
		} catch (FileNotFoundException e) {
			createFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


}
